package com.chenfan.process.service.impl;

import java.util.Collections;
import java.util.List;
import java.util.Optional;

import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chenfan.process.common.constants.CommonFieldConstants;
import com.chenfan.process.entity.po.ProcessCarbonCopyPo;
import com.chenfan.process.enums.BooleanEnum;
import com.chenfan.process.repository.ProcessCarbonCopyRepository;
import com.chenfan.process.service.ProcessCarbonCopyService;

/**
 * @author liuming
 * @date 2021/8/13
 */
@Service
public class ProcessCarbonCopyServiceImpl extends ServiceImpl<ProcessCarbonCopyRepository, ProcessCarbonCopyPo>
    implements ProcessCarbonCopyService {

    @Override
    public Optional<List<ProcessCarbonCopyPo>> listByProcessId(Long approvalTemplateId, Long processId) {
        QueryWrapper<ProcessCarbonCopyPo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(CommonFieldConstants.STATUS, BooleanEnum.N.getCode());
        queryWrapper.eq(ProcessCarbonCopyPo.PROCESS_ID, processId);
        queryWrapper.eq(ProcessCarbonCopyPo.APPROVAL_TEMPLATE_ID, approvalTemplateId);
        List<ProcessCarbonCopyPo> list = this.list(queryWrapper);
        if (CollectionUtils.isEmpty(list)) {
            return Optional.of(Collections.emptyList());
        }
        return Optional.of(list);
    }

    @Override
    public Optional<List<ProcessCarbonCopyPo>> listByProcessId(Long approvalTemplateId, List<Long> processId) {
        QueryWrapper<ProcessCarbonCopyPo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(CommonFieldConstants.STATUS, BooleanEnum.N.getCode());
        queryWrapper.in(ProcessCarbonCopyPo.PROCESS_ID, processId);
        queryWrapper.eq(ProcessCarbonCopyPo.APPROVAL_TEMPLATE_ID, approvalTemplateId);
        List<ProcessCarbonCopyPo> list = this.list(queryWrapper);
        if (CollectionUtils.isEmpty(list)) {
            return Optional.of(Collections.emptyList());
        }
        return Optional.of(list);
    }
}
